<?php

namespace Mem;

use MemLib\MemBase;
use MemLib\Pdb;

/**
 * 后台登陆信息表
 *
 * @version 1.0
 * @author 张云江
 */
class MemAuth_User extends MemBase
{
    public function __construct()
    {
        parent::__construct("db_auth", "t_auth_user");
    }

    public function insertWithParam($login_name, $nick_name, $login_pwd, $status, $insert_dt)
    {
        $login_name = \MemLib\PublicFunc::convertToHtml($login_name);
        $nick_name = \MemLib\PublicFunc::convertToHtml($nick_name);
        $login_pwd = \MemLib\PublicFunc::convertToHtml($login_pwd);
        $status = (int)$status;
        $insert_dt = \MemLib\PublicFunc::convertToDate($insert_dt);
        $insertdata = array(
            "login_name" => $login_name,
            "nick_name" => $nick_name,
            "login_pwd" => $login_pwd,
            "status" => $status,
            "insert_dt" => $insert_dt
        );
        $ret = $this->addData($insertdata);
        return $ret;
    }

    /**
     * 登陆
     * @param double $user_id
     * @return array
     */
    public function getInfoWithLogin($login_name, $login_pwd)
    {
        $sql = "SELECT * FROM t_auth_user WHERE login_name='{$login_name}' AND login_pwd='{$login_pwd}';";
        $data = $this->getData($sql, "getInfoWithLogin:{$login_name} login_pwd:{$login_pwd}");
        return $data ? $data[0] : array();
    }

    /**
     * 更新用户状态
     * @param mixed $uid
     * @param mixed $status 0启用，1禁用
     * @return \Mem\mixed
     */
    public function updateDataWithStatus($uid, $status)
    {
        $uid = (float)$uid;
        $status = (int)$status;
        $updatedata = array(
            "status" => $status
        );
        $updatewhere = array(
            "uid" => $uid
        );
        return $this->updateData($updatedata, $updatewhere);
    }

    /**
     * 删除用户
     * @param mixed $uid
     * @return \Mem\mixed
     */
    public function deleteInfoWithUid($uid)
    {
        $uid = (float)$uid;
        $deldata = array(
            "uid" => $uid
        );
        return $this->deleteData($deldata);
    }

    /**
     * 更新用户密码
     * @param mixed $uid
     * @param mixed $status 0启用，1禁用
     * @return \Mem\mixed
     */
    public function updateDataWithLogin_pwd($uid, $login_pwd)
    {
        $uid = (float)$uid;
        $login_pwd = \MemLib\PublicFunc::convertToHtml($login_pwd);
        $updatedata = array(
            "login_pwd" => $login_pwd
        );
        $updatewhere = array(
            "uid" => $uid
        );
        return $this->updateData($updatedata, $updatewhere);
    }
}
